//
//  NRWCarListShareCell.m
//  New_Runway
//
//  Created by 张记 on 2018/5/28.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "NRWCarListShareCell.h"
@interface NRWCarListShareCell ()
@property (weak, nonatomic) IBOutlet UIImageView *leftImage;
@property (weak, nonatomic) IBOutlet UIImageView *rightImage;
@property (weak, nonatomic) IBOutlet UIImageView *mainImage;
@property (weak, nonatomic) IBOutlet UIButton *shareBtn;
@property (weak, nonatomic) IBOutlet UILabel *priceL;
@property (weak, nonatomic) IBOutlet UILabel *contentL;
@property (weak, nonatomic) IBOutlet UILabel *mainTitle;

@end
@implementation NRWCarListShareCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.shareBtn.layer.masksToBounds = YES;
    self.shareBtn.layer.cornerRadius = 5;
    
}
-(void)setIndex:(NSIndexPath *)index{
    _index = index;
}
-(void)setCarModel:(Result *)carModel{
    _carModel = carModel;
    
    [self.mainImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@.r_240xh_170",ImageApi,carModel.carImageUrl]] placeholderImage:[UIImage imageNamed:@"tu"]];
    self.mainTitle.text =carModel.carTitle;
    
    self.rightImage.image = [UIImage imageNamed:@""];;
    
    if (carModel.carOrderState == 1 ) {
        self.rightImage.image = [UIImage imageNamed:@"mark-b"];;
    }
    if (carModel.carBargainPriceState == 1 ) {
        self.rightImage.image = [UIImage imageNamed:@"mark-c"];;
    }
    
    if (carModel.carRetailPrice <= 0) {
        self.priceL.text = @"价格面议";
        
    }else{
        self.priceL.text =  [NSString stringWithFormat:@"%.2f万",(CGFloat)carModel.carRetailPrice];
    }
    
    NSString *mileageStr;
    if ([carModel.carMileage doubleValue] <= 0) {
        mileageStr = @"未输入里程";
    }else{
        
        if ([carModel.carMileage doubleValue] < 0.1) {
            mileageStr = [NSString stringWithFormat:@"%.f公里", [carModel.carMileage doubleValue] *10000];
            
        }else{
            mileageStr = [NSString stringWithFormat:@"%.2f万公里", [carModel.carMileage doubleValue]];
            
        }
        
    }
    if (carModel.carLicenceState == 1 ) {
        
        self.contentL.text = [NSString stringWithFormat:@"%@ | %@年",mileageStr, [NRWCarTurnTime timestampSwitchTime:carModel.carLicenceDate andFormatter:@"YYYY"]];
    }else if (carModel.carLicenceState == 2){
        self.contentL.text = [NSString stringWithFormat:@"%@ | 未上牌",mileageStr];
    }else if (carModel.carLicenceState == 3 ){
        self.contentL.text = [NSString stringWithFormat:@"%@ | 新车",mileageStr];
    }
    if (carModel.carAuthState == 0) {
        self.leftImage.hidden = YES;
    }else{
        self.leftImage.hidden = NO;
    }
    
}

- (IBAction)shareThisCar:(id)sender {
    [self routerEventWithName:@"share" userInfo:@{@"index" : self.index}];

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
